package ee.falcon.gui.frame.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

import ee.falcon.gui.frame.ProfilesFrame;
import ee.falcon.util.ErrorMessager;
import ee.falcon.xml.ProfileInfoXMLModifier;
import ee.falcon.xml.SpecificProfileInfo;

public class DeleteButtonListener implements ActionListener
{
	private ProfilesFrame profile; 
	private ProfileInfoXMLModifier profileInfoXMLModifier; 
	private Map<String, SpecificProfileInfo> profileInfoHashMap; 
	
	public DeleteButtonListener(ProfilesFrame profile, ProfileInfoXMLModifier profileInfoXMLModifier,
			Map<String, SpecificProfileInfo> profileInfoHashMap)
	{
		this.profile = profile; 
		this.profileInfoXMLModifier = profileInfoXMLModifier; 
		this.profileInfoHashMap = profileInfoHashMap; 
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		
		try 
		{
			profileInfoXMLModifier.deleteProfileFromProfileInfoXML(profile.getSpecificProfileInfoJListSelection(), 
						profile, profileInfoHashMap);
		} 
		catch (ParserConfigurationException e1) 
		{
			new ErrorMessager().errorMsg(ErrorMessager.ERR002R_FAIL_TO_CONFIGURE_PARSER, e1);
		}
		//renew GUI information
		profile.getProfileInfoList().renewData();
		profile.getProfilesFrameJListEditor().renewJListData();
		//profile.renewJListData();
	}

}
